package model;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import dao.GetCnn;
import entity.Lienhe;

public class LienheModel {
	public int countnewlienhe() throws SQLException{
		SanphamModel model = new SanphamModel();
		int sodong =  model.getTotalRows("select * from lienhe where trangthai = N'Chưa xem'");
		return sodong;
	}
	public void updatetrangthai() throws SQLException{
		Connection cnn = GetCnn.getCnn();
		Statement stat = cnn.createStatement();
		String sSQL = "update lienhe set trangthai = N'Xem rồi' where trangthai = N'Chưa xem'";
		stat.executeUpdate(sSQL);
	}
	public List<Lienhe> getlistlienhe(String strSearch) throws  SQLException{
		List<Lienhe> list = new ArrayList<Lienhe>();
		Connection cnn = GetCnn.getCnn();
		Statement stat = cnn.createStatement();
		ResultSet rs = stat.executeQuery(strSearch);
		while (rs.next()){
			Lienhe entity = new Lienhe();
			entity.setHoten(rs.getString("hoten"));
			entity.setEmail(rs.getString("email"));
			entity.setNoidung(rs.getString("noidung"));
			entity.setDienthoai(rs.getString("dienthoai"));
			entity.setTrangthai(rs.getString("trangthai"));
			list.add(entity);
		}
		return list;
	}

}
